#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2022, Andrey Kunitsyn
# Copyright (c) 2022, Nikolay Semenov
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":board:feather-rp2040"
    module.description = """\
# Adafruit Feather RP2040

A board with RP2040 chip and 8MB of flash memory.

https://www.adafruit.com/product/4884

See `modm:rp-pico` for programming instructions.
"""

def prepare(module, options):
    if not options[":target"].partname.startswith("rp2040"):
        return False

    module.depends(
        ":platform:clock",
        ":platform:core",
        ":platform:gpio",
        ":platform:usb",
        ":platform:clockgen")
    return True

def build(env):
    env.outbasepath = "modm/src/modm/board"
    env.substitutions = {
        "with_logger": False,
        "with_assert": env.has_module(":architecture:assert")
    }
    env.template("../board.cpp.in", "board.cpp")
    env.copy('.')

    env.outbasepath = "modm/openocd/modm/board/"
    env.copy(repopath("tools/openocd/modm/rp2040_picoprobe.cfg"), "rp2040_picoprobe.cfg")
    env.collect(":build:openocd.source", "modm/board/rp2040_picoprobe.cfg")
